package com.xingchi.tornado.security.model;

import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.Setter;
import org.springframework.security.authentication.AbstractAuthenticationToken;
import org.springframework.security.core.GrantedAuthority;

import java.util.ArrayList;
import java.util.Collection;

/**
 * 微信小程序认证Token
 */
@Getter
@Setter
@EqualsAndHashCode(callSuper = true)
public class WxMiniProgramAuthenticationToken extends AbstractAuthenticationToken {

    /**
     * 小程序code码
     */
    private String code;

    /**
     * 昵称
     */
    private String nickName;

    /**
     * 头像
     */
    private String avatar;

    /**
     * 性别
     */
    private String gender;

    /**
     * 创建未认证的Token
     */
    public WxMiniProgramAuthenticationToken() {
        super(new ArrayList<>());
    }

    /**
     * 创建已认证的Token
     */
    public WxMiniProgramAuthenticationToken(String code, Collection<? extends GrantedAuthority> authorities) {
        super(authorities);
        super.setAuthenticated(true);
    }

    @Override
    public Object getCredentials() {
        return code;
    }

    @Override
    public Object getPrincipal() {
        return code;
    }
}
